package com.yfp.common.core.text;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * Boolean序列化器
 * null 值为 false
 */
public class BoolSerializer extends JsonSerializer<Boolean> {

    @Override
    public void serialize(Boolean value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value == null) {
            gen.writeBoolean(false); // 将 null 或未设置的布尔值序列化为 false
        } else {
            gen.writeBoolean(value); // 正常序列化
        }
    }
}